package main
import "fmt"

// 定义接口 Reder, Writer
type Reader interface{
	Read() string
}

type Writer interface{
	Write(data string) int
}

// 定义组合接口 fileOpt
type fileOpt interface{
	Reader
	Writer
}

// 定义结构体 File
type File struct{
	path string
	mode int
	auther string
	context string
}

func (f File) Read() string{
	return fmt.Sprintf("author:%s\ncontext:%s", f.auther, f.context)
}

// 修改为指针接收者, 才能修改结构体中的字段
// func (f File) Write(data string) int{
func (f *File) Write(data string) int{
	f.context = data
	return len(data)
}

func main(){
	var fp fileOpt = &File{
		path: "/tmp/test.log",
		mode: 0644,
		auther: "admin",
	}
	fp.Write("this is a test log")
	fmt.Println(fp.Read())
}